// http://newhtml.net/web-audio-api%E7%AE%80%E6%98%93%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B/
// https://github.com/ClassicOldSong/WPE-Audio-Simulator/blob/master/src/main.js
// https://sagittarius-rev.gitbooks.io/understanding-ecmascript-6-zh-ver/content/chapter_2.html#the-repeat---method
'use strict'
export default function () {
  let ctx = new AudioContext()

  let play = (buffer) => {
    let source = ctx.createBufferSource()
    source.buffer = buffer
    source.connect(ctx.destination) // connect hardware
    console.log(source)
  }

  let req = new XMLHttpRequest();
  req.open('get', 'life.mp3', true)
  req.responseType = 'arraybuffer'
  req.onload = () => {
    ctx.decodeAudioData(req.response, buffer => play(buffer))
  }
  req.send()
}
